// ==UserScript==
// @name         NGA回复状态增强
// @icon         https://bbs.nga.cn/favicon.ico
// @namespace    http://tampermonkey.net/
// @version      0.0.1-2024-11-14
// @description  在主题内显示显示楼层的部分额外状态
// @include      /^https?://(bbs\.ngacn\.cc|nga\.178\.com|bbs\.nga\.cn|ngabbs\.com)/read.+/
// @author       AgMonk
// @homepage     https://gitee.com/AgMonk/tampermonkey-script
// @downloadURL https://gitee.com/AgMonk/tampermonkey-script/raw/master/nga/nga-reply-status.user.js
// @updateURL https://gitee.com/AgMonk/tampermonkey-script/raw/master/nga/nga-reply-status.user.js
// ==/UserScript==

(function() {
    'use strict';
    setTimeout(function(){
        // 状态全表
        const statusTable = [
            {position:1,tag:"隐藏"},
            {position:5,tag:"被举报"},
            {position:6,tag:"不再提示"},
            {position:9,tag:"审核中"},
            {position:14,tag:"审核中"},
            {position:26,tag:"审核不通过"},
        ];


        [...document.getElementsByClassName('forumbox postbox')].forEach(table=>{
            // 原始代码

            const parent = table.getElementsByTagName('h3')[0].parentElement

            const script = table.nextElementSibling.innerText.replace(/\n/g,'')
            const matcher = /commonui\.postArg\.proc\((.+)\)if/.exec(script)
            if (!matcher) return
            const paramString = matcher[1].replace(/'(.*?)'/g,(s)=>s.replace(/,/g,"||"))
            const params = paramString.split(',').filter(s=>!s.startsWith('$'))
            const type = parseInt(params[4])
            const status = statusTable.filter(i=>(Math.pow(2,i.position) & type)>0)
            const div = document.createElement('div')
            div.style= "color:red"
            parent.appendChild(div)
            status.map(i=>{
                const span = document.createElement('span')
                span.innerText = `[${i.tag}]`
                return span
            }).forEach(i=>div.appendChild(i))
        })

    },1000);
    // Your code here...
})();
